import { ref } from "vue";
import { defineStore } from "pinia";
import { useTabsStore } from "@/store/modules/tabs";
import { getSystemName, getSystyemModules } from "@/mctp-api/global/index";
/**
 * @description: 授权
 * @param {*} defineStore
 * @return {*}
 */
export const useAuthStore = defineStore("auth", () => {
  const id = ref<number | undefined>(undefined);
  const userInfo = ref<any>({});
  const tabsStore = useTabsStore();
  const systemName = ref("");
  const calibrationName = ref("开场校准管理器");

  /**
   * @description: 获取用户信息
   * @return {*}
   */
  const getLoginUserInfo = async () => {
    try {
    } catch (error) {
      if ((error as Error).message.indexOf("Request aborted") !== -1) {
        return;
      }
      return Promise.reject(error);
    }
  };

  /**
   * @description: 获取系统名称
   * @return {*}
   */
  const getSystemNameFn = () => {
    return new Promise(async (resolve) => {
      const { data } = await getSystemName();
      systemName.value = data || "";
      document.title = data || "";
      resolve(data);
    });
  };

  return {
    id,
    getLoginUserInfo,
    userInfo,
    getSystemNameFn,
    systemName,
    calibrationName
  };
});
